package com.heihei.combine.applist;

import com.heihei.combine.util.DirFlagUtil;
import com.heihei.constant.MessageConstant;
import com.heihei.decompression.ComDemoExe;
import com.heihei.util.ConfigUtilF;
import com.heihei.util.FileUtilF;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

/**
 *  压缩
 *
 * @version 1.0
 * @since JDK1.8
 * @author duanhengfei
 * @date 2021年02月01日 11:08:00
 */
public class ComPress {
    private static String COM_PASSWORD;
    static {
        Properties properties = ConfigUtilF.getProperties();
        try{
            COM_PASSWORD = properties.getProperty("comPress.password").trim();
        } catch (NullPointerException e) {
            COM_PASSWORD = null;
        }
    }

    public static void main(String[] args) throws IOException {
        start();
    }

    public static void start(boolean isOutline) throws IOException {
        System.out.println("请输入目标文件夹");
        File filePath = FileUtilF.getValidSrcDir();
        Integer flag = DirFlagUtil.getFlag();
        switch (flag) {
            case 1:
                System.out.println("当前目录");
                ComDemoExe.comPress(filePath, COM_PASSWORD);
                if(isOutline) {
                    FileUtilF.outLineOneLevelFile(filePath);
                }
                System.out.println(MessageConstant.CONGRATULATIONS + "压缩完成，请前往该目录查看：" + filePath.getParentFile().getAbsolutePath());
                break;
            case 2:
                System.out.println("子目录");
                for (File file : filePath.listFiles()) {
                    if(file.isDirectory()) {
                        ComDemoExe.comPress(file, COM_PASSWORD);
                        if(isOutline) {
                            FileUtilF.outLineOneLevelFile(file);
                        }
                    }
                }
                System.out.println(MessageConstant.CONGRATULATIONS + "全部压缩完成，请前往该目录查看：" + filePath.getAbsolutePath());
                break;
            default:
                System.out.println("没有该选项，退出压缩模式");
                break;
        }
    }

    public static void start() throws IOException {
        start(false);
    }
}